home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-27 | 1.7 KB | 91 lines | [TEXT/MPS ] |
- #ifndef __CDENT__
- #include "cdent.h"
- #endif
-
- #ifndef __DFILE__
- #include "DFile.h"
- #endif
-
- #ifndef __STRING__
- #include <string.h>
- #endif
-
-
-
- //µ DFile::IDFile
- #pragma segment DFile
- short DFile::IDFile(const DFile *anArea)
- {
- fOutput = anArea->fOutput;
- return (IDataArea(anArea));
- }
-
-
- //µ DFile::SetOutput
- #pragma segment DFile
- void DFile::SetOutput(StdFile *anOutput)
- {
- // If changing files, write the data that's accumulated so far into the
- // given output file.
- if (fOutput != anOutput && fOutput != 0)
- Flush();
- fOutput = anOutput;
- }
-
-
- //µ DFile::Putc
- #pragma segment DFile
- void DFile::Putc(int aChar)
- {
- char c = (char)aChar;
-
- if (Write(&c, sizeof(char)) != sizeof(char))
- diag(kFatal, "Out of memory in DFile::Putc\n");
- }
-
-
- //µ DFile::Puts
- #pragma segment DFile
- void DFile::Puts(const char *aString)
- {
- int aLen = strlen(aString);
-
- if (Write(aString, aLen) != aLen)
- diag(kFatal, "Out of memory in DFile::Puts\n");
- Putc('\n');
- }
-
-
- //µ DFile::Flush
- #pragma segment DFile
- size_t DFile::Flush(size_t aThreshold)
- {
- if (fOutput == 0)
- return (0);
-
- // If there is less data than the threshold, return 0. ClearErr() on
- // fOutput so that after calling Error() and getting the information that
- // no error occurred, the caller knows that no data was written because
- // the threshold was not reached.
- if (aThreshold > GetCursor()) {
- fOutput->ClearErr();
- return (0);
- }
-
- // Move the data to a safe place and make sure it doesn't move.
- MoveHHi();
- HLock();
-
- // Write the data.
- size_t amtWritten = fOutput->Write(GetData(0), GetCursor());
-
- // All done, unlock the data, clear the buffer for more data
- HUnlock();
- SetCursor(0);
-
- // Return the amount written
- return (amtWritten);
- }
-
-
-